import {Http} from '@angular/http';
import {NgLayer, NgLayerRef} from 'ng2-layer';
import {Component,ViewContainerRef, Injectable}  from '@angular/core';
import { Router, Params } from '@angular/router';
/**
 * 左侧菜单部分
 */
@Component({
	selector: '.category',
	templateUrl: 'template/router/pay/bindWx.html'
})
export class BindWxComp {
	bindData = {};
	
	constructor(private http:Http, private layer:NgLayer, private router:Router){
		this.http.get({
			search:{
				m:"Admin",
				c:"ApiWallet",
				a:"get_user_wallet"
			}
		}).then((d)=>{
			this.bindData = d.data.info;
			if(d.data.is==1){
				this.router.navigateByUrl('/pay');
			}
		});
	}
	
	/**
	 * 绑定微信
	 */
	bindWx(){
		this.loading = true;
		this.http.post({
			search:{
				m:"Admin",
				c:"ApiWallet",
				a:"bound_user_wallet"
			},
			body:{
				id_card:this.bindData.id_card,
				name:this.bindData.name
			}
		}).then((data)=>{
			this.loading = false;
			if(data.code == 200){
				this.router.navigateByUrl('/pay');
			}
		});
	}
	
	/**
	 * 弹窗扫码
	 */
	openWechat(){
		let top = (screen.height-520)/2,
			left = (screen.width-400)/2;
			
		let win = window.open('https://open.weixin.qq.com/connect/qrconnect?appid=wx2fa04ec2138ba0ca&redirect_uri=http%3A%2F%2Fapi.txiaoyuan.cn%2Findex%2Ft.php%3Fm%3DAdmin%26c%3DWx%26a%3Dbind_wallet_code&response_type=code&scope=snsapi_login&state=3d6be0a4035d839573b04816624a415e#wechat_redirect',
			'', "width=400,scrolling=no,height=520,resizable=0,top=150,left=$left".replace("$left", left));
		
		setInterval(()=>{
			win.postMessage('http://192.168.56.1:8020/', 'http://api.txiaoyuan.cn/');
		}, 1000);
			
		window.addEventListener('message', (e)=>{
			console.log(e);
		}, false);
		
	}
}